package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.sc.nft.entity.OpenPage;
import com.sc.nft.entity.vo.AdminOpenPageVO;
import com.sc.nft.mapper.OpenPageMapper;
import lombok.extern.slf4j.Slf4j;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

/**
 * 开屏页表(sc_open_page)数据DAO
 *
 * @author Tangzehui
 * @since 2023-11-22 15:56:37
 * @description 
 */
@Slf4j
@Repository
public class OpenPageDao extends ServiceImpl<OpenPageMapper, OpenPage> {

    public Page<AdminOpenPageVO> pageAdmin(String firstTitle, int pageNo, int pageSize){
        return baseMapper.pageAdmin(new Page<>(pageNo,pageSize), firstTitle);
    }

    public OpenPage getOpenOne(){
        LambdaQueryWrapper<OpenPage> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OpenPage::getIsOpen, Boolean.TRUE);
        queryWrapper.last("limit 1");
        return getOne(queryWrapper);
    }

    public Boolean closeOpenPage(){
        return baseMapper.closeOpenPage();

    }

    public Boolean deleteById(Long id){
        return SqlHelper.retBool(baseMapper.deleteById(id));
    }

    public Boolean updateById(Long id, String firstTitle, String image){
        OpenPage openPage = new OpenPage();
        openPage.setFirstTitle(firstTitle);
        openPage.setImage(image);
        openPage.setId(id);
        return openPage.updateById();
    }
}